package com.draven.mq.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/product")
public class ProductSender {

    @Resource
    private AmqpTemplate rabbitAmqpTemplate;

    //exchange交换器名称
    @Value("${mq.config.exchange}")
    private String exchange;

    @Value("${mq.routing.product.info}")
    private String productRoutingKeyInfo;

    @Value("${mq.routing.product.error}")
    private String poductRoutingKeyError;

    @Value("${mq.routing.product.warn}")
    private String poductRoutingKeyWarn;

    @Value("${mq.routing.product.debug}")
    private String poductRoutingKeyDebug;


    @Value("${mq.routing.order.info}")
    private String orderRoutingKeyInfo;

    @Value("${mq.routing.order.error}")
    private String orderRoutingKeyError;

    @Value("${mq.routing.order.warn}")
    private String orderRoutingKeyWarn;

    @Value("${mq.routing.order.debug}")
    private String orderRoutingKeyDebug;


    @GetMapping("/send/product")
    public void sendProduct() {
        rabbitAmqpTemplate.convertAndSend(exchange, productRoutingKeyInfo, "hello rabbitMQ:mq.routing.product.info");
        rabbitAmqpTemplate.convertAndSend(exchange, poductRoutingKeyError, "hello rabbitMQ：mq.routing.product.error");
        rabbitAmqpTemplate.convertAndSend(exchange, poductRoutingKeyWarn, "hello rabbitMQ：mq.routing.product.warn");
        rabbitAmqpTemplate.convertAndSend(exchange, poductRoutingKeyDebug, "hello rabbitMQ：mq.routing.product.debug");
    }

    @GetMapping("/send/order")
    public void sendOrder() {
        rabbitAmqpTemplate.convertAndSend(exchange, orderRoutingKeyInfo, "hello rabbitMQ:mq.routing.order.info");
        rabbitAmqpTemplate.convertAndSend(exchange, orderRoutingKeyError, "hello rabbitMQ：mq.routing.order.error");
        rabbitAmqpTemplate.convertAndSend(exchange, orderRoutingKeyWarn, "hello rabbitMQ：mq.routing.order.warn");
        rabbitAmqpTemplate.convertAndSend(exchange, orderRoutingKeyDebug, "hello rabbitMQ：mq.routing.order.debug");
    }
}
